package ywj;

import java.util.Scanner;

public class Clazz {
    Teacher[] t1 = new Teacher[10];

    int num = 0;

    public void add(Teacher t) {
        t1[num] = t;
        num++;
    }

    public void del(int i) {
        int j;

        for (j = 1; j < num; j++) {
            t1[j] = t1[j + 1];
        }
        num--;
    }

    public void change(int i, Teacher s) {
        t1[i] = s;
    }

    public int que(String name) {
        int i = 0;
        for (i = 0; i < num; i++) {
            if (t1[i].getName().equals(name)) {
                return i + 1;
            }
        }
        return 0;
    }

    public void display() {
        int i;
        System.out.println("年龄\t姓名\t性别");
        for (i = 0; i < num; i++) {
            System.out.printf("%c\t%s\t%d\n", t1[i].sex, t1[i].name, t1[i].age);
        }
    }

    public static void main(String[] args) {
        Clazz c1 = new Clazz();
        int i;
        Scanner sc = new Scanner(System.in);

        do {
            System.out.println("教师管理系统");
            System.out.println("请输入：0添加 1删除 2修改 3查询");

            i = sc.nextInt();

            switch (i) {
                case 0: {
                    do {
                        System.out.println("请输入姓名：");
                        String name = sc.next();
                        System.out.println("请输入性别：");
                        char sex = sc.next().charAt(0);
                        System.out.println("请输入年龄：");
                        int age = (int) sc.nextInt();
                        c1.add(new Teacher(name, sex, age));
                        System.out.println("是否继续：Y|N");
                    } while (sc.next().equals("Y"));
                    c1.display();
                }
                break;
                case 1: {
                    System.out.println("请输入要删除教师的姓名：");
                    String name = sc.next();
                    int q = c1.que(name);
                    c1.del(q - 1);
                    c1.display();
                }
                break;
                case 2:{
                    System.out.println("请输入要修改教师的姓名：");
                    String name=sc.next();
                    int q=c1.que(name);
                    System.out.println("请输入修改后姓名：");
                    String name1=sc.next();
                    System.out.println("请输入修改后年龄：");
                    int age1=sc.nextInt();
                    System.out.println("请输入修改后性别：");
                    char sex1=sc.next().charAt(0);
                    c1.change(q-1, new Teacher(name1, (char) age1,sex1));
                    c1.t1[q-1].setName(name1);
                    c1.t1[q-1].setSex(sex1);
                    c1.t1[q-1].setAge(age1);
                }
                break;
                case 3:{
                    System.out.println("请输入要查询的姓名：");
                    String name=sc.next();
                    int n=c1.que(name);
                    if(n!=0) {
                        System.out.printf("第%d个教师的信息是：%d\t%s\t%d\n", n,c1.t1[n-1].getSex(),c1.t1[n-1].getName(),c1.t1[n-1].getAge());
                    }else {
                        System.out.println("未找到该教师信息！");
                    }
                    break;
                }
                default:
                    System.out.println("你输入的有错误，程序结束");
                    break;

            }
            System.out.println("是否继续 Y|N");
        }while (sc.next().equals("Y"));
    }
    private static Teacher teacher(String name1,int age1,char sex1){


        return null;
    }
}
